$(document).ready(function() {
	$('#role_form').validate({
		errorElement: 'div',
		errorClass: 'help-block',
		focusInvalid: false,
		ignore: "",			
		errorPlacement: function (error, element) {
			if(element.is('.select2')) {
				error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
			}else if(element.is('.chosen-select')) {
				error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
			}else error.insertAfter(element.parent());
		},
		submitHandler: function (form) {
		},
		invalidHandler: function (form) {
		}
	});
	$('.role-profile-feed').ace_scroll({
		size: 480,
		mouseWheelLock: true,
		alwaysVisible : true
	});
	
	$(document.body).on('click','.btn-cancel',function(){
		$(parent.document.body).find('#superFrameModal').remove();
	});

	$(document.body).on('click','.btn-save',function(){
		if(!$('#role_form').valid()){
			alert("数据验证失败！");
		 	return false;
		}
		$.ajax({ 
			url: root+'/role/save',
			contentType: "application/json",
		    type: "POST",
		    data:JSON.stringify($("#role_form").serializeJson()),
			success: function(data){
				if(data.result==0){
					parent.window.location.reload();
				}else{
					alert('保存失败！');
				}
			}
		});
	});
	$('.my-date-picker').datepicker({autoclose:true});
	$('.chosen-select').chosen({allow_single_deselect:true}); 
});
